﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Windows.Forms;

namespace _04_SmtpClient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            tLogin.Text = "kovanjko.oleg@gmail.com";
        }

        private void bSend_Click(object sender, EventArgs e)
        {
            MailMessage mailMessage = new MailMessage(new MailAddress("kovanjko.oleg@gmail.com"), new MailAddress("e.mikitka@gmail.com"));
            mailMessage.Subject = "Test";
            mailMessage.Body = tbText.Text;
           // mailMessage.Attachments
            

            SmtpClient client = new SmtpClient("smtp.gmail.com", 587/*465*/);
            client.Credentials = new NetworkCredential(tLogin.Text, tPassword.Text);
            client.EnableSsl = true;

            try
            {
                client.Send(mailMessage);
                MessageBox.Show("OK");

            }catch(SmtpException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

       
    }
}
